import { Injectable } from '@angular/core';
import { Stacks } from '../../type';
import { Observable,of } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class StockService {
  private stacks: Stacks[];
  constructor() {
    this.stacks = [
      new Stacks(1, 'React', 99, 0, 10, ['Frontend', 'JavaScript']),
      new Stacks(2, 'Angular', 89, 3, 12, ['Frontend', 'TypeScript']),
      new Stacks(3, 'Vue', 79, 4.7, 2, ['Frontend', 'JavaScript']),
      new Stacks(4, 'Node.js', 120, 5, 15, ['Backend', 'JavaScript']),
      new Stacks(5, 'Express', 95, 4, 11, ['Backend', 'JavaScript']),
      new Stacks(6, 'NestJS', 110, 3, 14, ['Backend', 'TypeScript']),
      new Stacks(7, 'Django', 130, 2.7, 16, ['Backend', 'Python']),
      new Stacks(8, 'Flask', 85, 5, 9, ['Backend', 'Python']),
      new Stacks(9, 'Spring Boot', 1, 4.6, 18, ['Backend', 'Java']),
      new Stacks(10, 'Laravel', 100, 0.5, 13, ['Backend', 'PHP']),
    ]
  }
  getStacks() {
    return this.stacks
    // return   of(this.stacks)
  }
  getStack(id: number):Stacks  {
    let stack = this.stacks.find(stack => stack.id == id);
    if (!stack) {
      stack = new Stacks(0, '', 0, 0, 0, ['Frontend', 'JavaScript'])
    }
    return stack
  }
}
